/*
 * Project: BoboDesignPattern
 * 
 * File Created at 2019年12月16日
 * 
 * Copyright 2012 Greenline.com Corporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Greenline Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Greenline.com.
 */
package test.practice;

import java.util.Arrays;

/**
 * @Type A20191216_fastsort
 * @Desc
 * @author 52489
 * @date 2019年12月16日
 * @Version V1.0
 */
public class A20191216_fastsort {

    public static void main(String[] args) {
        int[] nums = { 3, 2, 1, 7, 8, 4, 6, 5 };
        System.out.println(Arrays.toString(fastsort(nums, 0, nums.length - 1)));
    }

    /**
     * @param nums
     * @param i
     * @param j
     */
    private static int[] fastsort(int[] nums, int start, int end) {
        if (start < end) {
            int left = start;
            int right = end;
            int key = nums[start];
            while (left < right) {
                while (nums[right] > key && right > left) {
                    right--;
                }
                nums[left] = nums[right];
                while (nums[left] < key && left < right) {
                    left++;
                }
                nums[right] = nums[left];
            }
            nums[left] = key;
            fastsort(nums, start, left);
            fastsort(nums, left + 1, end);
        }

        return nums;
    }

}
